#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;

int n, h[N], p[N], c[N], b[N], tot;
ll f[2][N], sc[N], sp[N];

namespace seg {
	ll val[N << 2], tg[N << 2];
	inline void pt(int x, ll v) { tg[x] += v; val[x] += v; }
	inline void pd(int x) { if(tg[x]) pt(x << 1, tg[x]), pt(x << 1 | 1, tg[x]), tg[x] = 0; }
	inline void pu(int x) { val[x] = max(val[x << 1], val[x << 1 | 1]); }
	inline void reset() { memset(val, 0xcf, sizeof val); memset(tg, 0, sizeof tg); }
	inline void upd(int pos, ll v, int o = 1, int l = 0, int r = tot) {
		if(l == r) return val[o] = max(val[o], v), void(); int mid = l + r >> 1; pd(o);
		if(pos <= mid) upd(pos, v, o << 1, l, mid); else if(pos > mid) upd(pos, v, o << 1 | 1, mid + 1, r); pu(o);
	}
	inline void upd(int xl, int xr, int v, int o = 1, int l = 0, int r = tot) {
		if(xl == l && xr == r) return pt(o, v); int mid = l + r >> 1; pd(o);
		if(xr <= mid) upd(xl, xr, v, o << 1, l, mid); else if(xl > mid) upd(xl, xr, v, o << 1 | 1, mid + 1, r);
		else upd(xl, mid, v, o << 1, l, mid), upd(mid + 1, xr, v, o << 1 | 1, mid + 1, r); pu(o);
	}
	inline ll query(int xl, int xr, int o = 1, int l = 0, int r = tot) {
		if(xl == l && xr == r) return val[o]; int mid = l + r >> 1; pd(o);
		if(xr <= mid) return query(xl, xr, o << 1, l, mid); else if(xl > mid) return query(xl, xr, o << 1 | 1, mid + 1, r);
		else return max(query(xl, mid, o << 1, l, mid), query(mid + 1, xr, o << 1 | 1, mid + 1, r));
	}
}

void solve(ll *f) {
	seg :: reset(); seg :: upd(0, 0);
	rep(i, 1, n) {
		f[i] = seg :: query(0, h[i]) + p[i];
		seg :: upd(0, h[i] - 1, -c[i]);
		seg :: upd(h[i], f[i]);
	}
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	n = in; rep(i, 1, n) h[i] = b[++tot] = in, p[i] = in, c[i] = in;
	sort(b + 1, b + tot + 1); tot = unique(b + 1, b + tot + 1) - b - 1;
	rep(i, 1, n) h[i] = lower_bound(b + 1, b + tot + 1, h[i]) - b;
	solve(f[0]); reverse(h + 1, h + n + 1); reverse(p + 1, p + n + 1); reverse(c + 1, c + n + 1); solve(f[1]);
	ll ans = 0;
	rep(i, 1, n) ans = max(ans, f[0][n - i + 1] + f[1][i] - p[i]);
	cout << ans << endl; return 0;
}
